/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 artifact_prop_spell_charges.h

	$Header: /heroes4/artifact_prop_spell_charges.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( ARTIFACT_PROP_SPELL_CHARGES_H_INCLUDED )
#define ARTIFACT_PROP_SPELL_CHARGES_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "artifact_prop_single_spell.h"

namespace t_artifact_prop
{
	// ----------------------------------------------------------------------
	// class for spell charges
	// ----------------------------------------------------------------------
	class t_spell_charges_base : public t_single_spell
	{
	public:
		void init( t_spell spell, int charges, int charge_rate = 2 );

		virtual bool accept( t_artifact_effect_visitor& visitor );
		int          get_max_spell_points() const;
		int          get_recharge_rate() const;
		int          get_spell_points() const;
		virtual bool read( std::streambuf& buffer );
		void         recharge();
		void         reset_spell_points();
		void         set_recharge_rate( int arg );
		void         use_spell_points( int amount );
		virtual bool write( std::streambuf& buffer ) const;
	protected:
		int m_spell_points;
		int m_recharge_rate;
	};

	inline void t_spell_charges_base::init( t_spell spell, int charges, int charge_rate )
	{
		t_single_spell::init( spell, k_artifact_target_hero, charges );
		m_recharge_rate = charge_rate;
		reset_spell_points();
	}

	inline int t_spell_charges_base::get_recharge_rate() const
	{
		return m_recharge_rate;
	}

	inline int t_spell_charges_base::get_spell_points() const
	{
		return m_spell_points;
	}

	inline void t_spell_charges_base::recharge()
	{
		m_spell_points += m_recharge_rate;
		if (m_spell_points > get_max_spell_points())
			m_spell_points = get_max_spell_points();
	}

	inline void t_spell_charges_base::reset_spell_points()
	{
		m_spell_points = get_max_spell_points();
	}

	inline void t_spell_charges_base::set_recharge_rate( int arg )
	{
		m_recharge_rate = arg;
	}

	inline void t_spell_charges_base::use_spell_points( int amount )
	{
		m_spell_points -= amount;
		if (m_spell_points < 0)
			m_spell_points = 0;
	}

	typedef t_effect< t_spell_charges_base, k_artifact_effect_spell_charges > t_spell_charges;

	inline t_spell_charges* get_spell_charges( t_spell spell, int charges, int charge_rate = 2 )
	{
		return new t_spell_charges( spell, charges, charge_rate );
	}

};

#endif // ARTIFACT_PROP_SPELL_CHARGES_H_INCLUDED